package com.demo.easyExcel.fillTemplateColor;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.metadata.fill.FillConfig;
import com.demo.easyExcel.APIDemo.read.FillData;
import com.demo.easyExcel.pojo.People;
import org.junit.Test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Start {
    /**
     * 复杂的填充
     *
     * @since 2.1.1
     */
    @Test
    public void complexFill() {
        String templateFileName = "C:\\Users\\Administrator\\Desktop\\template\\person.xls";

        String fileName = "C:\\Users\\Administrator\\Desktop\\template\\person2.xls";
        WriteSheet writeSheet = EasyExcel.writerSheet().build();
        ExcelWriter excelWriterBuild = EasyExcel
                .write(fileName)
                .withTemplate(fileName)
                .registerWriteHandler(new ExportAllFileCellColorHandler2())
                .build();
        HashMap<String, String> stringStringHashMap = new HashMap<>();
        stringStringHashMap.put("data", "111");
        excelWriterBuild
                .fill(data(), FillConfig.builder().forceNewRow(Boolean.TRUE).build(), writeSheet);
        excelWriterBuild.fill(stringStringHashMap, writeSheet);
        excelWriterBuild.finish();
    }

    private List<People> data() {
        List<People> peopleList = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            peopleList.add(new People(i + 1 + "", "wy", "18"));
        }
        return peopleList;
    }
}
